﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MixScript.BLL.FI
{
    public class rptGeneralJournal : cBaseBLL
    {

        public rptGeneralJournal() { }


        public bool getMataUang(out DataTable dt, int type)
        {
            string param = "";
            if (type == 1)
                param = "AND currency != 'IDR'";
            //param = "AND currency != (select currency from accinterface)";
            string sSql = @"select acctnum,acctname,currency from accaccounts where LEN(acctnum)=5 {0} order by acctnum";
            try
            {
                dt = Dbserver.ExecuteQuery(String.Format(sSql, param), "rpt");
                return dt.Rows.Count > 0;
            }
            catch (Exception ex) { throw ex; }
        }

        public bool getActivePeriod(out DataTable dt)
        {

            string sSql = @"declare @awal DATETIME,@akhir DATETIME
                        ,@diff INT DECLARE @Table TABLE(period  DATETIME NOT NULL)
                        SELECT @awal=awal,@akhir=akhir,@diff =DATEDIFF(MONTH,awal,akhir)  FROM accperiod where aktif = 1
                        --SELECT @awal,@akhir,@diff 
                        while @awal < @akhir
                        BEGIN
                        INSERT INTO @Table VALUES (@awal)

                        SET @awal = DATEADD(MONTH,1,@awal)
                        END
                        SELECT period ID,
                        CASE CAST(MONTH(period) AS NVARCHAR(5)) WHEN 1 THEN 'JAN'
                        WHEN 2 THEN 'FEB' WHEN 3 THEN 'MAR' WHEN 4 THEN 'APR' WHEN 5 THEN 'MAY'
                        WHEN 6 THEN 'JUL' WHEN 7 THEN 'JUN' WHEN 8 THEN 'AUG' WHEN 9 THEN 'SEP'
                        WHEN 10 THEN 'OCT' WHEN 11 THEN 'NOV' WHEN 12 THEN 'DEC'
                        END +' - '+CAST(YEAR(period)AS NVARCHAR(11)) AS NAME
                        from @Table";
            try
            {
                dt = Dbserver.ExecuteQuery(sSql, "activePeriod");
                return dt.Rows.Count > 0;
            }
            catch (Exception ex) { throw ex; }

        }
    }
}
